#! /bin/sh

# Test for:
#   https://bugs.debian.org/204249

: ${srcdir=.}
. "$srcdir/testlib.sh"

: ${MANDB=mandb}
: ${ACCESSDB=accessdb}

init
fake_config /usr/share/man /usr/X11R6/man
MANPATH="$tmpdir/usr/share/man:$tmpdir/usr/X11R6/man"
export MANPATH
db_ext="$(db_ext)"

write_page xterm 1x "$tmpdir/usr/X11R6/man/man1/xterm.1x.gz" \
	UTF-8 gz '' 'xterm \- terminal emulator for X'
mkdir -p "$tmpdir/usr/share/man/man1"
ln -s ../../../X11R6/man/man1/xterm.1x.gz \
      "$tmpdir/usr/share/man/man1/x-terminal-emulator.1.gz"
run $MANDB -C "$tmpdir/manpath.config" -u -q \
	"$tmpdir/usr/share/man:$tmpdir/usr/X11R6/man"
cat >"$tmpdir/1-share.exp" <<EOF
x-terminal-emulator -> "- 1 1 MTIME B - - gz terminal emulator for X"
EOF
cat >"$tmpdir/1-X11R6.exp" <<EOF
xterm -> "- 1x 1 MTIME A - - gz terminal emulator for X"
EOF
accessdb_filter "$tmpdir/usr/share/man/index$db_ext" >"$tmpdir/1-share.out"
accessdb_filter "$tmpdir/usr/X11R6/man/index$db_ext" >"$tmpdir/1-X11R6.out"
expect_pass '/usr/share/man x-terminal-emulator -> xterm' \
	    'diff -u "$tmpdir/1-share.exp" "$tmpdir/1-share.out"'
expect_pass '/usr/X11R6/man x-terminal-emulator -> xterm' \
	    'diff -u "$tmpdir/1-X11R6.exp" "$tmpdir/1-X11R6.out"'

./fspause
write_page uxterm 1x "$tmpdir/usr/X11R6/man/man1/uxterm.1x.gz" \
	UTF-8 gz '' \
	'uxterm \- X terminal emulator for Unicode (UTF-8) environments'
ln -sf ../../../X11R6/man/man1/uxterm.1x.gz \
      "$tmpdir/usr/share/man/man1/x-terminal-emulator.1.gz"
run $MANDB -C "$tmpdir/manpath.config" -u -q \
	"$tmpdir/usr/share/man:$tmpdir/usr/X11R6/man"
cat >"$tmpdir/2-share.exp" <<EOF
x-terminal-emulator -> "- 1 1 MTIME B - - gz X terminal emulator for Unicode (UTF-8) environments"
EOF
cat >"$tmpdir/2-X11R6.exp" <<EOF
uxterm -> "- 1x 1 MTIME A - - gz X terminal emulator for Unicode (UTF-8) environments"
xterm -> "- 1x 1 MTIME A - - gz terminal emulator for X"
EOF
accessdb_filter "$tmpdir/usr/share/man/index$db_ext" >"$tmpdir/2-share.out"
accessdb_filter "$tmpdir/usr/X11R6/man/index$db_ext" >"$tmpdir/2-X11R6.out"
expect_pass '/usr/share/man x-terminal-emulator -> uxterm' \
	    'diff -u "$tmpdir/2-share.exp" "$tmpdir/2-share.out"'
expect_pass '/usr/X11R6/man x-terminal-emulator -> uxterm' \
	    'diff -u "$tmpdir/2-X11R6.exp" "$tmpdir/2-X11R6.out"'

finish
